# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/custom-actions


# This is a simple example for a custom action which utters "Hello World!"

# from typing import Any, Text, Dict, List
#
# from rasa_sdk import Action, Tracker
# from rasa_sdk.executor import CollectingDispatcher
#
#
# class ActionHelloWorld(Action):
#
#     def name(self) -> Text:
#         return "action_hello_world"
#
#     def run(self, dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#
#         dispatcher.utter_message(text="Hello World!")
#
#         return []

from typing import Any, Text, Dict, List,Union
from rasa_sdk.forms import FormAction, EventType, SlotSet, Action

class WeatherForm(FormAction):
    def name(self) -> Text:
        return "weather_form"

    @staticmethod
    def required_slots(tracker: "Tracker") -> List[Text]:
        return ["date", "location"]

    def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict[Text, Any]]]]:
        return {
            "date":self.from_entity(entity="date"),
            "location":self.from_entity(entity="location")
        }

    def submit(
        self,
        dispatcher: "CollectingDispatcher",
        tracker: "Tracker",
        domain: "DomainDict",
    ) -> List[EventType]:
        date = tracker.get_slot('date')
        location = tracker.get_slot('location')

        result = "你需要查询{}{}的天气吗？".format(location, date)
        dispatcher.utter_message(result)
        return []